use chrono::{DateTime, Duration, Local};
use std::fs;

fn get_elapse(start: &str) -> Duration {
    let t = DateTime::parse_from_str(start, "%Y-%m-%d %H:%M:%S %z").unwrap(); 
    let local: DateTime<Local> = Local::now();
    return local.signed_duration_since(t);
}

fn get_birth_datetime() -> String {
   let b = fs::read("birth").unwrap(); 
   let birth = String::from_utf8(b).unwrap();
   return birth
}

fn main() {
    let t = get_birth_datetime();
    let str_birth = t.as_str();
    let stripped = match t.strip_suffix("\n") {
        Some(s) => s,
        None => str_birth,
    };
    let e = get_elapse(&stripped);

    let hours = e.num_hours();
    println!("宝宝已经{}天{}小时大了！", hours/24, hours%24);
}
